package qlsl.androiddesign.activity.subactivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;
import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.activity.commonactivity.MemberForgetPasswordActivity;
import qlsl.androiddesign.activity.commonactivity.MemberRegistActivity;
import qlsl.androiddesign.adapter.commonadapter.ForeignLoginGridAdapter;
import qlsl.androiddesign.http.service.commonservice.MemberService;
import qlsl.androiddesign.util.commonutil.Log;
import qlsl.androiddesign.view.baseview.FunctionView;
import qlsl.androiddesign.view.subview.commonview.Test2View;

public class Test2Activity extends BaseActivity implements OnItemClickListener {

	private Test2View functionView;

	private EditText et_account, et_password;

	private GridView gridView;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		functionView = new Test2View(this);
		setContentView(R.layout.activity_test);

		gridView = (GridView) findViewById(R.id.gridView);
		et_account = (EditText) findViewById(R.id.et_account);
		et_password = (EditText) findViewById(R.id.et_password);
		if (Log.isDebug) {
			et_account.setText("username");
			et_password.setText("123456");
		}
		initData();
		initListener();
	}

	protected void initData() {
		functionView.setGridViewData();
	}

	public void setAdapter(BaseAdapter adapter) {
		gridView.setAdapter(adapter);
	}

	protected void initListener() {
		gridView.setOnItemClickListener(this);
	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.btn_right:
			doClickRightButton();
			break;
		case R.id.btn_login:
			doClickLoginButton();
			break;
		case R.id.tv_forget_pwd:
			doClickForgetPwdView();
			break;
		}
	}

	private void doClickRightButton() {
		startActivity(MemberRegistActivity.class);
	}

	private void doClickLoginButton() {
		String account = et_account.getText().toString();
		String password = et_password.getText().toString();
		if (TextUtils.isEmpty(account)) {
			showToast("请输入手机号");
			return;
		}
		if (TextUtils.isEmpty(password)) {
			showToast("请输入密码");
			return;
		}
		if (password.length() < 6) {
			showToast("密码不得小于6位");
			return;
		}
		MemberService.loginByEmail(account, password, functionView, this);

	}

	private void doClickForgetPwdView() {
		startActivity(MemberForgetPasswordActivity.class);
	}

	public FunctionView<?> getFunctionView() {
		return functionView;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub

	}

}
